#include "editWindow.h"
#include <iostream>
#include <unistd.h>

editWindow::editWindow(int mode)
:
    btnOK("确定"),
    btnQuit("返回")
{
    if(mode==0)
        set_title("添加条目");
    else
        set_title("编辑条目");
    m_mode=mode;
    set_size_request(200,200);
    std::cout<<"editWindow PID:"<<getuid()<<std::endl;
    std::cout<<"father PID:"<<getppid()<<std::endl;

    entSetTitle.set_placeholder_text("输入标题");
    entSetTitle.set_expand(true);

    mCalender.set_size_request(100,100);
    mCalender.set_expand(true);

    buttonBox.set_orientation(Gtk::Orientation::HORIZONTAL);
    buttonBox.set_spacing(20);
    buttonBox.append(btnOK);
    buttonBox.append(btnQuit);
    buttonBox.set_halign(Gtk::Align::CENTER);

    boxFrame.set_orientation(Gtk::Orientation::VERTICAL);
    boxFrame.append(entSetTitle);
    boxFrame.append(mCalender);
    boxFrame.append(buttonBox);

    set_child(boxFrame);

    btnOK.signal_clicked().connect(sigc::mem_fun(*this,&editWindow::on_btnOK_clicked));
    btnQuit.signal_clicked().connect(sigc::mem_fun(*this,&editWindow::on_btnQuit_clicked));
}

editWindow::~editWindow() {}

void editWindow::on_Dialog_buttonEvent(int response_id)
{
    refInfDialog->hide();
}

void editWindow::on_btnOK_clicked()
{
    if(entSetTitle.get_text_length()==0)
    {
        refInfDialog.reset(new Gtk::MessageDialog(*this,"标题不能为空",false,Gtk::MessageType::ERROR,Gtk::ButtonsType::CANCEL,true));
        refInfDialog->set_hide_on_close(true);
        refInfDialog->signal_response().connect(sigc::mem_fun(*this,&editWindow::on_Dialog_buttonEvent));
        refInfDialog->show();
        return ;
    }
    newEidtRelease.title=entSetTitle.get_text();
    newEidtRelease.time=mCalender.get_date();
    m_signal_finish.emit(newEidtRelease,m_mode);
    this->hide();
}

void editWindow::on_btnQuit_clicked()
{
    this->hide();
}


